//
//  SEChatFileAuthorizeCell.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/6/16.
//

import UIKit

class SEChatFileAuthorizeCell: UITableViewCell {
    
    weak var delegate: SEChatCellDelegate?

    func update(with viewModel: SEChatViewModel) {
        statusLabel.isHidden = !viewModel.fileAuthorizeStatus.buttonHidden
        refuseButton.isHidden = viewModel.fileAuthorizeStatus.buttonHidden
        confirmButton.isHidden = viewModel.fileAuthorizeStatus.buttonHidden
        
        statusLabel.textColor = viewModel.fileAuthorizeStatus.statusTextColor
        statusLabel.text = viewModel.fileAuthorizeStatus.statusText
    }
    
    @IBAction private func confirmTapped() {
        delegate?.fileAuthorizeCell(self, didTappedWithStatus: .authorized)
    }
    
    @IBAction private func refuseTapped() {
        delegate?.fileAuthorizeCell(self, didTappedWithStatus: .refuse)
    }
    
    @IBOutlet private weak var containerView: UIView! {
        didSet {
            containerView.layer.cornerRadius = 6
            containerView.layer.borderColor = UIColor(hex: "#EBEBEB").cgColor
            containerView.layer.borderWidth = 1
            containerView.layer.masksToBounds = true
        }
    }
    
    @IBOutlet private weak var statusLabel: UILabel!
    
    @IBOutlet private weak var refuseButton: UIButton! {
        didSet {
            refuseButton.setTitle("否", for: .normal)
            refuseButton.setTitleColor(Asset.main.color, for: .normal)
            refuseButton.setTitleColor(Asset.main.color.withAlphaComponent(0.8), for: .highlighted)
            refuseButton.layer.cornerRadius = refuseButton.height / 2
            refuseButton.layer.borderWidth = 1
            refuseButton.layer.borderColor = Asset.main.color.cgColor
        }
    }
    
    @IBOutlet private weak var confirmButton: UIButton! {
        didSet {
            confirmButton.setTitle("是", for: .normal)
            confirmButton.setTitleColor(Asset.white.color, for: .normal)
            confirmButton.setTitleColor(Asset.white.color.withAlphaComponent(0.8), for: .highlighted)
            confirmButton.backgroundColor = Asset.main.color
            confirmButton.layer.cornerRadius = confirmButton.height / 2
        }
    }
}
